import { useDispatch, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import { logoutUser } from '../../store/userSlice';
import { RootState } from '../../store';

const Dashboard = () => {
  const dispatch = useDispatch();
  const navigate = useNavigate();
  const userInfo = useSelector((state: RootState) => state.user.userInfo);

  const handleLogout = () => {
    dispatch(logoutUser());
    navigate('/login');
  };

  return (
    <div className="dashboard-container">
      <h2>欢迎，{userInfo?.username || '管理员'}</h2>
      <button onClick={handleLogout}>退出登录</button>
    </div>
  );
};

export default Dashboard;